Completed
Push — master ( baabf5...12a59e )
by Warwick
03:22
created

customizer-font.js ➔ ... ➔ this.each   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 30
rs 9.16
c 0
b 0
f 0
1
/**
2
 * A small jquery plugin that does all of the hard work.
3
 */
4
jQuery( function( $ ) {
5
6
	$.fn.fontPickerCustomControl = function() {
7
8
		//return the 'this' selector to maintain jquery chainability
9
		return this.each(function() {
10
11
			// cache this selector for further use
12
			thisFontPickerCustomControl = this;
0 ignored issues
show
Bug introduced by
The variable thisFontPickerCustomControl seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.thisFontPickerCustomControl.
Loading history...
13
14
			// hide select box
15
			$("select", this).hide();
16
17
			// show fancy content
18
			$(".fancyDisplay", this).show();
19
20
			// add event listeners to fancy display
21
			$(".fancyDisplay ul li").on("click", function(event){
0 ignored issues
show
Unused Code introduced by
The parameter event is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
22
				// get index of clicked element
23
				var index = $(".fancyDisplay ul li", thisFontPickerCustomControl).index(this),
24
					clicked = $(this),
25
					parent = clicked.closest('.fancyDisplay');
26
27
				parent.find('.font-choice').removeClass('selected');
28
29
				// unselect all options
30
				$('select option', thisFontPickerCustomControl).removeAttr('selected');
31
32
				clicked.addClass('selected');
33
				// select new element
34
				// simulate a change
35
				$('select :nth-child('+(index+1)+')', thisFontPickerCustomControl).attr('selected', 'selected').change();
36
			});
37
38
		});
39
40
	};
41
42
} );
43